<!DOCTYPE html>
<html>

<head lang="en">
    <title>找攻略</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/strategyComment.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css"/>
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script src="/js/common.js"></script>
    <script>
        $(function () {
            var param = getParams();
            sessionStorage.setItem("strategyCommentId",param.id);
            //根据点评id 查出该点评 lituan
            $.get("/strategyComments", {id: param.id}, function (data) {
                console.log(data);
                $(".container").renderValues(data, {
                    getHref: function (item, value) {
                        var href = $(item).data("href")
                        $(item).prop("href", href + value);
                    },
                    getStar: function (item, value) {
                        var temp = "";
                        for (var i = 0; i < value; i++) {
                            temp += '<i class="fa fa-star"></i>';
                        }
                        for (var i = 0; i < 5 - value; i++) {
                            temp += ' <i class="fa fa-star-o"></i>';
                        }
                        $(item).html(temp);
                    }
                })


                //给图片绑定点击事件 lituan
                $(".comment-img li img").click(function () {
                    var img = $(this).attr("src");
                    $(document).dialog({
                        overlayClose: true,
                        titleShow: false,
                        content: '<img class="info-icon" width="100%" src="' + img + '"/>'
                    });

                })


                var user = JSON.parse(sessionStorage.getItem("user"));
                var id = data.user.id;
                //查询是否是关注状态
                $.get('/users/isAttention', {attentionuserId: user.id, beattentionuserId:id}, function (data) {
                    console.log(data);
                    if (data.success) {
                        $('#followBtn').html("取消关注").css("color", "orange");
                    } else {
                        $('#followBtn').html("关注").css("color", "orange");;
                    }
                })
                $('#followBtn').click(function () {
                    $.post("/users/attention", {attentionuserId: user.id, beattentionuserId:id}, function (data) {
                        if (data.success) {
                            $('#followBtn').html("关注").css("color", "orange");
                        } else {
                            $('#followBtn').html("取消关注").css("color", "orange");
                        }
                    });
                });

                var num ;//总数
                var state;
                //点赞总数
                $.get("/praises/nums", {travelId: param.id, type: 4}, function (data) {
                    num = data;
                    $("#num").html(num)
                })

                //点赞
                if (user) {
                    //用户登录且有点赞过显示红色
                    $.get("/praises", {travelId: param.id, userId: user.id, type: 4}, function (data) {
                        if (data) {
                            $("#likeBtn").css("color", "orange")
                        }
                    })
                } else {
                    //没有登录时该图标为黑色
                    $("#likeBtn").css("color", "")
                }

                //点赞或取消点赞
                $("#likeBtn").click(function () {
                    //判断该用户是否有点赞
                    $.get("/praises", {travelId: param.id, userId: user.id, type: 4}, function (data) {
                        if (data) {
                            $.ajax({
                                type: "delete",
                                url: "/praises/" + param.id+"/comment",
                                success: function () {
                                    $("#likeBtn").css("color", "")
                                }
                            });
                            state = false;
                        } else {
                            $.post("/praises", {travelId: param.id, userId: user.id, type: 4}, function (data) {
                                if (data.success) {
                                    $("#likeBtn").css("color", "orange")
                                }
                            })
                            state = true;
                        }

                        if (state) {
                            num++;
                        }else{
                            num--;
                        }
                        $("#num").html(num);
                    })
                })
            })

            //分页
            var currentPage = 1;
            var travelsDate = [];
            var pages;
            var flag = false;//表示当前没有在查询
            $(function () {
                function loadTravels() {
                    if (flag) {
                        return;

                    }
                    flag = true;
                    /*评论回复*/
                    $.get('/strategyComments/' + param.id + '/strategyUserComments', {currentPage: currentPage}, function (data) {
                        if (data) {
                            $.merge(travelsDate, data.list);
                            var ret = {"list": travelsDate}
                            $(".userComment").renderValues(ret, {
                                getHref: function (item, value) {
                                    var href = $(item).data("href")
                                    $(item).prop("href", href + value);
                                },
                                getJsonHref:function (item,value) {
                                    if (value) {
                                        var json=JSON.parse(value);
                                        $(item).prop("href","/mine/editComment.html?replyUserId="+json.replyUserId+"&strategyUserCommentId="+json.strategyUserCommentId)
                                    }
                                }
                            });
                        }



                        currentPage++
                        pages = data.pages;
                        flag = false;//表示查询完成
                    });

                }

                loadTravels();

                $(window).scroll(function () {
                    if ($(window).height() + $(document).scrollTop() + 1 >= $(document).height()) {
                        if (pages >= currentPage) {
                            loadTravels();
                        } else {
                            $(document).dialog({
                                type: 'notice',
                                infoText: '亲,到底了',
                                autoClose: 2500,
                                position: 'bottom'
                            });
                        }
                    }
                });

            })

            //如果地址栏上的state为list 就跳到消息列表
            if (param.state) {
                if (param.state=="list") {
                    $("#goHref").attr("href","/mine/strategyCommentList.html")
                }
            }



        })

    </script>
</head>

<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col">
            <a id="goHref" href="javascript:history.go(-1);">
                <span><i class="fa fa-chevron-left"></i></span>
            </a>
        </div>
        <div class="col">
            <span>点评详情</span>
        </div>
        <div class="col">

            <a href="/index.html" class="home">首页</a>
        </div>
    </div>
</div>

<div class="comment" >
    <div class="container ">
        <div class="row">
            <div class="col-2 comment-head">
                <a data-href="/userProfiles.html?id=" render-key="user.id" render-fun="getHref">
                    <img class="rounded-circle" render-src="user.headImgUrl">
                </a>
                <button class="btn" id="followBtn">
                    <i class="fa fa-hand-o-right"> </i> 关注
                </button>
            </div>
            <div class="col">
                <span class="comment-star" render-key="starNum" render-fun="getStar">

                </span>

                <span class="comment-date" render-html="commendTime"></span>
                <div class="comment-content">
                    <p render-content render-html="content"></p>
                </div>
                <ul class="comment-img" render-loop="imgArr">
                    <li>
                        <img render-src="imgArr.self">
                    </li>

                </ul>

                <div class="comment-link">
                    <a data-href="/strategyCatalogs.html?id="  render-key="strategy.id" render-fun="getHref">
                        <img render-src="strategy.coverUrl"> <span render-html="strategy.title"></span>
                        <i class="fa fa-angle-right fa-2x"></i>
                    </a>
                </div>

            </div>
        </div>
    </div>

    <div class="count d-flex justify-content-between">
        <div class="p-2">评论<span>0</span></div>
        <div class="p-2" id="likeBtn">赞
            <span id="num">0</span>
        </div>

    </div>

    <div class="userComment">
        <div render-loop="list">
            <!--user信息-->
            <div>
                <a href="/user/?id=47949308" class="cl_ava" >
                    <img style="width: 30px" render-src="list.user.headImgUrl">
                </a>

                <a href="/user/?id=47949308" style="font-size: small" render-html="list.user.nickName"></a>
                <span render-html="list.createTime"></span>
                <div class="cl_con">
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <span render-html="list.content"></span>
                    <a class="replyBtn" style="font-size: xx-small" render-key="list.json" render-fun="getJsonHref" >回复</a>
                </div>
                <!--二级回复-->
                <div render-loop="list.replyUserComments">
                    <div>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <span render-html="list.replyUserComments.createTime"></span><br/>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <!--回复人头像-->
                        <a data-href="/userProfiles.html?id=" render-key="list.replyUserComments.user.id" render-fun="getHref">
                            <img style="width: 15px" render-src="list.replyUserComments.user.headImgUrl">
                        </a>
                        <!--回复人姓名-->
                        <a data-href="/userProfiles.html?id=" render-key="list.replyUserComments.user.id" render-fun="getHref"
                           render-html="list.replyUserComments.user.nickName">
                        </a>
                        <span style="font-size: xx-small" >回复</span>
                        <!--被复人头像-->
                        <a data-href="/userProfiles.html?id=" render-key="list.replyUserComments.replyUser.id" render-fun="getHref" >
                            <img style="width: 15px" render-src="list.replyUserComments.replyUser.headImgUrl">
                        </a>
                        <!--被复人姓名-->
                        <a  data-href="/userProfiles.html?id=" render-key="list.replyUserComments.replyUser.id" render-fun="getHref"
                            render-html="list.replyUserComments.replyUser.nickName"></a> :
                        <span render-html="list.replyUserComments.content"></span>
                        &nbsp;&nbsp;
                        <!--回复按钮-->
                        <a render-key="list.replyUserComments.json" render-fun="getJsonHref"   style="font-size: xx-small" >回复</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="comment-list">
    快来发表你的评论吧

</div>

<div class="operation">
    <div class="d-flex justify-content-between">
        <div class="p-2"><i class="fa fa-commenting-o"></i>
            <a   id="commentBtn"   style="font-size: xx-small" >添加你的评论</a>
        </div>
        <script>
            $("#commentBtn").prop("href","/mine/editComment.html?strategyId="+getParams().id)
        </script>
        <div class="p-2"><i class="fa fa-star-o"></i> 收藏</div>
    </div>
</div>


<script>
    $(function () {

    })
</script>
</body>

</html>